﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using ScrumTable.Common;

#endregion


namespace ScrumTable.DL.Data.Generic.Cache
{
    /// <summary>
    /// This class contains a simple implementation of the identity interface.
    /// </summary>
    public class CacheIdentity : ICacheIdentity
    {
        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the default id of a cache identity.
        /// </summary>
        public const int DefaultId = -1;

        /// <summary>
        /// Gets the default unique id of a cache identity.
        /// </summary>
        public const string DefaultUniqueId = "";

        /// <summary>
        /// Gets the default revision of a cache identity.
        /// </summary>
        public const int DefaultRevision = -1;


        /// <summary>
        /// Gets the tfs id of the element. Caution: This id is unique in
        /// the current storage only.
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// Returns true if the current element contains has an id assigned.
        /// </summary>
        public bool HasId { get { return (Id != DefaultId); } }

        /// <summary>
        /// Gets the global unqiue id of the tfs element.
        /// </summary>
        public string UniqueId { get; private set; }

        /// <summary>
        /// Gets the revision (server side versioning information) of the current element.
        /// </summary>
        public int Revision { get; private set; }

        /// <summary>
        /// Gets the identity category (element type).
        /// </summary>
        public string Category { get; private set; }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="CacheIdentity"/> class.
        /// </summary>
        /// <param name="uniqueId">Specifies the id which is propagated to the business layer / data driver.</param>
        /// <param name="category">Specifies the underlying id category (which specifies the id type).</param>
        /// <param name="id">Specifies the internal data layer id.</param>
        /// <param name="revision">Specifies the revision of the element in tfs.</param>
        public CacheIdentity(string uniqueId, string category, int id = DefaultId, int revision = DefaultRevision)
        {
            PreCondition.AssertNotNullOrEmpty(uniqueId, "uniqueId");
            PreCondition.AssertNotNullOrEmpty(category, "category");

            Id = id;
            UniqueId = uniqueId;
            Revision = revision;
            Category = category;
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        #endregion

        #region Events

        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion


    }
}